﻿Public Partial Class WFrm_Alternativa_Seleccion_Unica_ConImagen
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ViewState("usuario") = Request("usuario")
            ViewState("K_TIPO_PREGUNTA") = Request("K_TIPO_PREGUNTA")
            ViewState("K_PREGUNTA") = Request("K_PREGUNTA")

            Caga_Inicial()
            CargarAlternativas()
        End If


    End Sub
    Sub Caga_Inicial()
        For i = 1 To 100
            Dim item As New ListItem
            item.Value = i
            item.Text = i
            i_puntos.Items.Add(item)
            i_puntos.UpdateAfterCallBack = True
        Next
    End Sub
    Sub CargarAlternativas()
        Dim Execute As New CLS_DISENIO_ALTERNATIVA
        Dim rp As New DotNetResponse.SQLPersistence

        Execute.GetAlternativa(rp, ViewState("K_PREGUNTA"))

        Grid_Respuestas.DataSource = rp.DtTable
        Grid_Respuestas.DataBind()
        Grid_Respuestas.UpdateAfterCallBack = True
    End Sub
    Protected Sub Btn_Agregar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Agregar.Click
        Dim Execute As New CLS_DISENIO_ALTERNATIVA
        Dim rp As New DotNetResponse.SQLPersistence
        Dim im1 As Byte() = FileUpload1.FileBytes
        Dim im2 As Byte() = FileUpload2.FileBytes
        Dim im3 As Byte() = FileUpload3.FileBytes
        Dim im4 As Byte() = FileUpload4.FileBytes
        Dim im5 As Byte() = FileUpload5.FileBytes



        If Not IO.Directory.Exists(Server.MapPath("IMG" & ViewState("K_PREGUNTA"))) Then
            IO.Directory.CreateDirectory(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\")
        End If

        If im1.Length > 0 Then FileUpload1.SaveAs(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\F_" & Me.i_fila.Text & "_" & s_r1.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", ""))
        If im2.Length > 0 Then FileUpload2.SaveAs(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\F_" & Me.i_fila.Text & "_" & s_r2.ID & "." & FileUpload2.PostedFile.ContentType().Replace("image/", ""))
        If im3.Length > 0 Then FileUpload3.SaveAs(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\F_" & Me.i_fila.Text & "_" & s_r3.ID & "." & FileUpload3.PostedFile.ContentType().Replace("image/", ""))
        If im4.Length > 0 Then FileUpload4.SaveAs(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\F_" & Me.i_fila.Text & "_" & s_r4.ID & "." & FileUpload4.PostedFile.ContentType().Replace("image/", ""))
        If im5.Length > 0 Then FileUpload5.SaveAs(Server.MapPath("IMG" & ViewState("K_PREGUNTA")) & "\F_" & Me.i_fila.Text & "_" & s_r5.ID & "." & FileUpload5.PostedFile.ContentType().Replace("image/", ""))

        Dim url1 As String = "./IMG" & ViewState("K_PREGUNTA") & "/F_" & Me.i_fila.Text & "_" & s_r1.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")
        Dim url2 As String = "./IMG" & ViewState("K_PREGUNTA") & "/F_" & Me.i_fila.Text & "_" & s_r2.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")
        Dim url3 As String = "./IMG" & ViewState("K_PREGUNTA") & "/F_" & Me.i_fila.Text & "_" & s_r3.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")
        Dim url4 As String = "./IMG" & ViewState("K_PREGUNTA") & "/F_" & Me.i_fila.Text & "_" & s_r4.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")
        Dim url5 As String = "./IMG" & ViewState("K_PREGUNTA") & "/F_" & Me.i_fila.Text & "_" & s_r5.ID & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")


        Execute.AddAlternativa(rp, 0, ViewState("K_TIPO_PREGUNTA"), ViewState("K_PREGUNTA"), i_fila.SelectedValue, s_r1.Text, s_r2.Text, s_r3.Text, s_r4.Text, s_r5.Text, s_correcta.Checked, i_puntos.SelectedValue, im1, im2, im3, im4, im5, ViewState("usuario"), ViewState("usuario"), Now, Now, url1, url2, url3, url4, url5)

        Grid_Respuestas.DataSource = rp.DtTable
        Grid_Respuestas.DataBind()
        Grid_Respuestas.UpdateAfterCallBack = True


    End Sub

    Sub CargaImagenesEnGrilla()
        '11
        '".\IMG" & ViewState("K_PREGUNTA")) & "\F_" & i & "_" &  Grid_Respuestas.Rows(i).Cells (4).Text.Trim & "." & FileUpload1.PostedFile.ContentType().Replace("image/", "")

        'Dim i As Integer
        'For i = 0 To Grid_Respuestas.Rows.Count - 1
        '    '11      

        '    If 
        'Next

    End Sub

    Protected Sub Grid_Respuestas_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Grid_Respuestas.SelectedIndexChanged

    End Sub
End Class